$(document).ready(function (){
    var strName = "";
    var contTimeButton = "";
    var interval;
    /**
     * retrieve password
     * @author nonglei
     * @date  30/07/2014
     */
    $("#retrievePassword").click(function(){
        if($(this).attr('disabled') == 'disabled')
        {
            return;
        }
        strName = $("#retrievePassword").text();
        contTimeButton = "#retrievePassword";
        $(this).attr('disabled','');
        var urlArg = $(this).attr('url');
        var username = $("#sentverifyform-username").val();
        var email = $("#sentverifyform-email").val();
        var dataArg = "data=1&username="+username+"&email="+email;
        var successArg = function(data){
            if(data.type == 5)
            {
                $("#retrievePassword").text(data.sec);
                interval = setInterval(countTime, 1000);
            }
            else if(data.type != 4)
            {
                $("#retrievePassword").removeAttr('disabled');
            }
            else
            {
                $("#retrievePassword").text("60");
                interval = setInterval(countTime, 1000);
           }
            alert(data.message);
        };
        ajaxConstruction(urlArg, dataArg, "JSON", successArg);
    });
   /**
     * modify email
     * @author nonglei
     * @date  30/07/2014
     */
    $("#modifyEmail").click(function(){
        if($(this).attr('disabled') == 'disabled')
        {
            return;
        }
        if (!confirm("是否确定要修改绑定邮箱？(Are you sure you want to modify the binding email address)"))
        {
            return false;
        }
        strName = $(this).text();
        contTimeButton = "#modifyEmail";
        $(this).attr('disabled','');
        var urlArg = $(".onlineStatusBar #url").attr("value") + "/verify/modifyEmail";
        var dataArg = "data=1";
        var successArg = function(data){
            if(data.type == 5)
            {
                $("#modifyEmail").text(data.sec);
                interval = setInterval(countTime, 1000);
            }
            else if(data.type != 2)
            {
                $("#modifyEmail").removeAttr('disabled');
            }
            else
            {
                $("#modifyEmail").text("60");
                interval = setInterval(countTime, 1000);
           }
            alert(data.message);
        };
        ajaxConstruction(urlArg, dataArg, "JSON", successArg);
    });
    function countTime()
    {
        var sec = $(contTimeButton).text();
        sec = sec - 1;
        $(contTimeButton).text(sec);
        if(sec <= 0)
        {
            clearInterval(interval);
            $(contTimeButton).text(strName);
            $(contTimeButton).removeAttr('disabled');
        }
    }

});

